/*
 * TestUI.cpp
 */
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "UIEngine.h"
#include "UIWindow.h"
#include "UIText.h"
#include "UIPNGImage.h"
#include "UIJPGImage.h"

UIEngine* ui;

void renderUI() {
  glLoadIdentity();
  glMatrixMode(GL_MODELVIEW);

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  //UIWindow* win = new UIWindow(-0.5, -0.5, "App Test");
  //UIImage* img = new UIPNGImage(0, 0, 1, 1, "texture.png");
  UIImage* img = new UIJPGImage(0, 0, 1, 1, "texture.jpg");
  //win->add(img);
  //ui->addUIComponent(win);
  ui->addUIComponent(img);
  ui->addUIComponent(new UIText(UIText::STDTEXT, -0.5, -0.5, 0.3, 0, "Test UIText",
      RGBAColor(0., 0., 1., 1.)));
  ui->display();

  glFlush();
  glutSwapBuffers();
}

void key(unsigned char c, int x, int y) {
  switch (c) {
  case 27:
    delete ui;
    exit(0);
    break;
  }
}

int main(int argc, char* argv[]) {
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
  glutInitWindowSize(400, 400);
  glutCreateWindow("TestUI");
  glutDisplayFunc(renderUI);
  glutKeyboardFunc(key);
  glutSwapBuffers();

  // init GL
  glClearColor(0.8, 0.8, 0.8, 0.8);
  glShadeModel(GL_SMOOTH);
  glEnable(GL_DEPTH_TEST);

  // load the UI engine
  ui = new UIEngine(RGBAColor(1., 1., 1., 1.), RGBAColor(0., 0., 0., 0.), 1.,
      1., 0.01, 0.01);

  glutMainLoop();

  return 0;
}
